#ifndef HSPELL_H
#define HSPELL_H

#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QSet>
#include "hunspell.h"
#include <QtCore/QSettings>
#include <QtCore/QDir>


class HSpell : public QSettings
{
    Q_OBJECT
private:
    Hunhandle* m_handle;

    static QString appName () { return QString ("hspell"); }
    static QString dicPath ()
    {
        return QString ("%1/.%2/").arg (QDir::homePath ()).arg (appName ());
    }

    static const char * toPChar (const QString& string)
    {
        return string.toUtf8 ().constData ();
    }

public:
    HSpell ();
    ~HSpell ();

    int spell (const QString & word);
    bool isUnknown (const QString & word);

    QStringList suggestionsFor (const QString& word);

    QStringList misspelledWords (const QString& text);
    QStringList dicList ();

    QStringList analyse (const QString &word);
    QStringList stem (const QString& word);		// stem = "tronc"
    QStringList stem2 (const QString &word);
    void generate ();
    void generate2 ();

    //---------------------
    // gestion du dico

    void add (const QString &word);
    void addWithAffix ();
    void remove (const QString &word);

    //---------------------
    // correction d'un texte

    static QString replaced (const QString &text, const QString &bad, const QString &good);

    //-------------------
    // settings

    QString currentDic ();
    QString currentAff ();

public slots:
    void setCurrentDic (const QString& dic);
    void setCurrentAff (const QString& aff);
};


//DLL Hunhandle *Hunspell_create(const char * affpath, const char * dpath);

//DLL Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath,
//    const char * key);

//DLL void Hunspell_destroy(Hunhandle *pHunspell);

///* spell(word) - spellcheck word
// * output: 0 = bad word, not 0 = good word
// */
//DLL int Hunspell_spell(Hunhandle *pHunspell, const char *);

//DLL char *Hunspell_get_dic_encoding(Hunhandle *pHunspell);

///* suggest(suggestions, word) - search suggestions
// * input: pointer to an array of strings pointer and the (bad) word
// *   array of strings pointer (here *slst) may not be initialized
// * output: number of suggestions in string array, and suggestions in
// *   a newly allocated array of strings (*slts will be NULL when number
// *   of suggestion equals 0.)
// */
//DLL int Hunspell_suggest(Hunhandle *pHunspell, char*** slst, const char * word);

// /* morphological functions */

// /* analyze(result, word) - morphological analysis of the word */

//DLL int Hunspell_analyze(Hunhandle *pHunspell, char*** slst, const char * word);

// /* stem(result, word) - stemmer function */

//DLL int Hunspell_stem(Hunhandle *pHunspell, char*** slst, const char * word);

// /* stem(result, analysis, n) - get stems from a morph. analysis
//  * example:
//  * char ** result, result2;
//  * int n1 = Hunspell_analyze(result, "words");
//  * int n2 = Hunspell_stem2(result2, result, n1);
//  */

//DLL int Hunspell_stem2(Hunhandle *pHunspell, char*** slst, char** desc, int n);

// /* generate(result, word, word2) - morphological generation by example(s) */

//DLL int Hunspell_generate(Hunhandle *pHunspell, char*** slst, const char * word,
//    const char * word2);

// /* generate(result, word, desc, n) - generation by morph. description(s)
//  * example:
//  * char ** result;
//  * char * affix = "is:plural"; // description depends from dictionaries, too
//  * int n = Hunspell_generate2(result, "word", &affix, 1);
//  * for (int i = 0; i < n; i++) printf("%s\n", result[i]);
//  */

//DLL int Hunspell_generate2(Hunhandle *pHunspell, char*** slst, const char * word,
//    char** desc, int n);

//  /* functions for run-time modification of the dictionary */

//  /* add word to the run-time dictionary */

//DLL int Hunspell_add(Hunhandle *pHunspell, const char * word);

//  /* add word to the run-time dictionary with affix flags of
//   * the example (a dictionary word): Hunspell will recognize
//   * affixed forms of the new word, too.
//   */

//DLL int Hunspell_add_with_affix(Hunhandle *pHunspell, const char * word, const char * example);

//  /* remove word from the run-time dictionary */

//DLL int Hunspell_remove(Hunhandle *pHunspell, const char * word);

//  /* free suggestion lists */

//DLL void Hunspell_free_list(Hunhandle *pHunspell, char *** slst, int n);




//class HSpell : public Hunspell
//{

//public:

////    Constructor and destructor
////        Hunspell’s constructor needs paths of the affix and dictionary files. See the hunspell(4) manual page for
////        the dictionary format. Optional key parameter is for dictionaries encrypted by the hzip tool of the Hunspell
////        distribution.


//	HSpell (const QString &affpath = ":/hdics/fr-classique+reforme1990.aff",
//			const QString &dpath =":/hdics/fr-classique+reforme1990.dic");
//	HSpell (const QString & affpath, const QString & dpath, const QString &  key);
//	~HSpell () { }

////    Extra dictionaries
////        The add_dic() function load an extra dictionary file. The extra dictionaries use the affix file of the allocated
////        Hunspell object. Maximal number of the extra dictionaries is limited in the source code (20).

//	int addDic (const QString & dicPath);
//	int addDic (const QString & dicPath, const QString & key);

////    Spelling and correction
////         The spell() function returns non-zero, if the input word is recognised by the spell checker, and a zero value
////         if not. Optional reference variables return a bit array (info) and the root word of the input word. Info bits
////         checked with the SPELL_COMPOUND, SPELL_FORBIDDEN or SPELL_WARN macros sign compound
////         words, explicit forbidden and probably bad words. From version 1.3, the non-zero return value is 2 for the
////         dictionary words with the flag "WARN" (probably bad words).
////         The suggest() function has two input parameters, a reference variable of the output suggestion list, and an
////         input word. The function returns the number of the suggestions. The reference variable will contain the
////         address of the newly allocated suggestion list or NULL, if the return value of suggest() is zero. Maximal
////         number of the suggestions is limited in the source code.
////         The spell() and suggest() can recognize XML input, see the XML API section.

//	int spell (const QString & word);
//	int spell (const QString & word, int *info,  char **root);
//	int suggest (char***slst, const QString & word);

////    Morphological functions
////       The plain stem() and analyze() functions are similar to the suggest(), but instead of suggestions, return
////       stems and results of the morphological analysis. The plain generate() waits a second word, too. This extra
////       word and its affixation will be the model of the morphological generation of the requested forms of the first
////       word.
////       The extended stem() and generate() use the results of a morphological analysis:
////               char ** result, result2;
////               int n1 = analyze(&result, "words");
////               int n2 = stem(&result2, result, n1);
////       The morphological annotation of the Hunspell library has fixed (two letter and a colon) field identifiers, see
////       the hunspell(4) manual page.
////               char ** result;
////               char * affix = "is:plural"; // description depends from dictionaries, too
////               int n = generate(&result, "word", &affix, 1);
////               for (int i = 0; i < n; i++) printf("%s0, result[i]);

//	int analyze (char***slst, const QString & word);
//	int stem (char***slst, const QString & word);
//	int stem (char***slst,  QString *morph, int n);
//	int generate (char***slst, const QString & word, const QString & word2);
//	int generate (char***slst, const QString & word,  QString *desc, int n);

////    Memory deallocation
////       The free_list() function frees the memory allocated by suggest(), analyze, generate and stem() functions.

//	void freeList (QString **slst, int n);

////    Other functions
////        The add(), add_with_affix() and remove() are helper functions of a personal dictionary implementation to
////        add and remove words from the base dictionary in run-time. The add_with_affix() uses a second word as a
////        model of the enabled affixation of the new word.
////        The get_dic_encoding() function returns "ISO8859-1" or the character encoding defined in the affix file
////        with the "SET" keyword.
////        The get_csconv() function returns the 8-bit character case table of the encoding of the dictionary.
////        The get_wordchars() and get_wordchars_utf16() return the extra word characters definied in affix file for
////        tokenization by the "WORDCHARS" keyword.

//	int add (const QString & word);
//	int addWithAffix (const QString & word, const QString & example);
//	int remove (const QString & word);
//	QString  getDicEncoding ();
//	const QString &  getWordchars ();
//	unsigned short * getWordcharsUtf16 (int *len);
//	struct cs_info * getCsconv ();

////    The get_version() returns the version string of the library.

//

//};

#endif // HSPELL_H
